Imports MIMS.WRS.Business
Imports MIMS.WRS.Entities
Imports MIMS_WRS.Web

Public Class CustomerReservedList
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents rptList As MyFramework.Web.UI.WebControls.Repeater
    Protected WithEvents crContent As MyFramework.Web.UI.WebControls.ContentRegion
    Protected WithEvents pageTitle As MyFramework.Web.UI.WebControls.ContentRegion
    Protected WithEvents Masterpage1 As MyFramework.Web.UI.WebControls.MasterPage
    Protected WithEvents ddlCustomer As System.Web.UI.WebControls.DropDownList
    Protected WithEvents btnGo As System.Web.UI.WebControls.Button
    Protected WithEvents btnAdd As System.Web.UI.WebControls.LinkButton

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Security.IsCustomer Then
            Throw New Exception("You are not allowed here")
        End If
        If Not IsPostBack Then
            ddlCustomer.DataSource = USERService.GetCustomerList()
            ddlCustomer.DataTextField = USERColumns.LOGIN_NAME.ToString()
            ddlCustomer.DataValueField = USERColumns.US_ID_PK.ToString()
            ddlCustomer.DataBind()
            ddlCustomer.Items.Insert(0, New ListItem("[All]", "-1"))

            ddlCustomer.SelectedIndex = ddlCustomer.Items.IndexOf(ddlCustomer.Items.FindByValue(RequestContext.UserID.ToString()))

            Dim totalRecords As Integer
            If (RequestContext.DoReport) Then
                rptList.DataSource = CustomerProductService.GetCustomerProducts(RequestContext.UserID, CustomerProductColumns.ReservedDate, _
                    MyFramework.OrderDirection.ASC, 0, 0, totalRecords)
                rptList.DataBind()
            End If
        End If
    End Sub

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        Response.Redirect(String.Format("CustomerReservedList.aspx?uid={0}&dorpt=1", ddlCustomer.SelectedItem.Value))
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Response.Redirect("ReservedQtyDetail.aspx")
    End Sub

    Protected Function GetReservedQtyHTML(ByVal Container As Object) As String
        Dim reservedQty As Object = DataBinder.Eval(Container, "DataItem.ReservedQty")
        If (reservedQty Is DBNull.Value OrElse Convert.ToInt32(reservedQty).Equals(Nulls.NullInteger)) Then
            Return "&nbsp;"
        Else
            Return Convert.ToString(reservedQty)
        End If
    End Function

    Protected Function GetReservedDateHTML(ByVal Container As Object) As String
        Dim reservedDate As Object = DataBinder.Eval(Container, "DataItem.ReservedDate")
        If (reservedDate Is DBNull.Value OrElse Convert.ToDateTime(reservedDate).Equals(Nulls.NullDate)) Then
            Return "&nbsp;"
        Else
            Return Convert.ToDateTime(reservedDate).ToString(Config.DateFormat)
        End If
    End Function
End Class
